import {postAction} from '@/api/request'

export const homepageJs = {
    methods: {
        scroll() {
            this.scroll_begin = document.getElementById("scroll_begin");
            this.scroll_end = document.getElementById("scroll_end");
            this.scroll_div = document.getElementById("scroll_div");
            this.scroll_end.innerHTML = this.scroll_begin.innerHTML;
        },
        Marquee() {
            if (this.scroll_end.offsetWidth - this.scroll_div.scrollLeft <= 0) {
                this.scroll_div.scrollLeft -= this.scroll_begin.offsetWidth
            }
            else {
                this.scroll_div.scrollLeft++
            }
        },
        mEnter() {
            clearInterval(this.timer)
        },
        mLeave() {
            if (this.fileList.length > 2) {
                this.timer = setInterval(this.Marquee, this.speed)
            }
        },
        //获取柱状图数据
        getBarInfor(resolve) {
            var that = this;
            postAction(that.url.getHelpTypeStatistical, {areacode: that.areacode}).then((res) => {
                if (res.data.errcode == 0) {
                    that.bar.xAxisData = res.data.data.xAxisData;
                    that.bar.seriesData[0].data = res.data.data.seriesData0;
                    that.bar.seriesData[1].data = res.data.data.seriesData1;
                    that.$nextTick(() => {
                        that.$refs.bar.drawLine();
                    })
                }
            }).finally(() => {
                resolve(1);
            });
        },
        //获取饼图信息
        getPieInfor(resolve) {
            var that = this;
            postAction(that.url.getWorkAbilityStatistical, {areacode: that.areacode}).then((res) => {
                resolve(1);
                if (res.data.errcode == 0) {
                    this.pie.seriesData = res.data.data;
                    that.$nextTick(() => {
                        that.$refs.pie.drawLine();
                    });
                }
            }).finally(() => {
                resolve(1);
            });
        },
        getRadarInfor(resolve) {
            var that = this;
            postAction(that.url.getPowInforStatistical, {areacode: that.areacode}).then((res) => {
                if (res.data.errcode == 0) {
                    that.radar.seriesData[0].value = res.data.data.seriesData;
                    that.radar.indicator = res.data.data.indicator;
                    that.$nextTick(() => {
                        that.$refs.radar.drawLine();
                    })
                }
            }).finally(() => {
                resolve(1);
            });
        },
        getPieDoughnutInfor(resolve) {
            var that = this;
            postAction(that.url.getGenderStatistical, {areacode: that.areacode}).then((res) => {
                if (res.data.errcode == 0) {
                    that.pieDoughnut.seriesData = res.data.data;
                    that.$nextTick(() => {
                        that.$refs.pieDoughnut.drawLine();
                    })
                }
            }).finally(() => {
                resolve(1);
            });
        },
        //年龄段统计
        getFunnel(resolve) {
            var that = this;
            postAction(that.url.getAgeStatistical, {areacode: that.areacode}).then((res) => {
                if (res.data.errcode == 0) {
                    this.funnel.seriesData = res.data.data.seriesData;
                    this.funnel.legendData = res.data.data.legendData;
                    this.funnel.max = res.data.data.max;
                    that.$nextTick(() => {
                        that.$refs.funnel.drawLine();
                    })
                }
            }).finally(() => {
                resolve(1);
            });
        },
        //轮播信息
        getShuffling(resolve) {
            var that = this;
            postAction(that.url.getShuffling, {}).then((res) => {
                if (res.data.errcode == 0) {
                    that.fileList = res.data.data;
                    if (that.fileList.length > 2) {
                        that.scroll();
                        that.$nextTick(() => {
                            that.timer = setInterval(that.Marquee, that.speed);
                        })
                    }
                }
            }).finally(() => {
                resolve(1);
            });
        },
        //待办任务列表
        getToTasksList(resolve) {
            var that = this;
            postAction(that.url.getToTasksList, {}).then((res) => {
                if (res.data.errcode == 0) {
                    that.ToTasksList = res.data.data;
                }
            }).finally(() => {
                resolve(1);
            });
        },
        //保障对象列表
        getSecurityPersonList(resolve) {
            var that = this;
            postAction(that.url.getSecurityPersonList, {}).then((res) => {
                if (res.data.errcode == 0) {
                    that.SecurityPersonList = res.data.data;
                }
            }).finally(() => {
                resolve(1);
            });
        },
        //低收入家庭列表
        getSecurityFamilyList(resolve) {
            var that = this;
            postAction(that.url.getSecurityFamilyList, {}).then((res) => {
                if (res.data.errcode == 0) {
                    that.SecurityFamilyList = res.data.data;
                }
            }).finally(() => {
                resolve(1);
            });
        },

        //获取人员下级区划
        getAreaList(resolve) {
            var that = this;
            postAction(that.url.getAreaList, {}).then((res) => {
                if (res.data.errcode == 0) {
                    that.areaList = res.data.data;
                }
            }).finally(() => {
                resolve(1);
            });
        }
    }
}